import { Component, OnInit, Input,ViewChild } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';

import { Service } from '../../../../server/server';
import { InitService } from '../../../../public/serve/init/init.service';
import { HintsService } from '../../../../public/serve/hints/hints.service';
import { CudTableService } from '../../../../public/serve/cud-table/cud-table.service';
import { RemoveTableService } from '../../../../public/serve/remove-table/remove-table.service';
import { appProductUrl } from '../../../product.url';
import { exportRefreshTable } from '../../../product.data';
import { ProductIndexingTaskContentTableComponent } from './../table/product-indexing-task-content-table.component';
import {appSynonymUrl} from '../../../../synonym/synonym.url';
declare var $: any;

@Component({
  selector: 'app-product-export',
  templateUrl: './product-export.component.html'
})
export class ProductExportComponent implements OnInit {

  constructor(
    private activatedRoute: ActivatedRoute,
    public initService: InitService,
    public removeTableService: RemoveTableService,
    public request: CudTableService,
    public server: Service,
    private hintsService: HintsService
  ) { }

  ngOnInit() {
    this.exportPathList();

    this.activatedRoute.queryParams.subscribe((p: Params) => {
			this.taskId = p['taskId'];
		});
  }

  public exportType:any;

  @Input() taskId: any;
  @ViewChild("table") table: ProductIndexingTaskContentTableComponent;

  /**
   * 导出标引结果
   */
  exportClick(v) {
    
    let data:any = {
      taskId: [''+this.taskId+''],
      productId: this.removeTableService.getRemoveTableId,
      exportType: 'xml',//v.exportType,
      createBy: this.server.getuserName(),
      description: v.description,
    }
    // for(let p of this.pathList){
    //   if(p.pathCode == v.exportPath){
    //     data.exportPath = p.path;
    //   }
    // }
    if(!this.taskId){
      data.productId = [];
      data.taskId = this.removeTableService.getRemoveTableId;
    }
    this.request.postRequest(this.server.baseUrl +appProductUrl.exportIndexingThemeWords, data).then((res: any) => {
      this.hintsService.messages(res.message, res.result_code);
      $("#productExport").modal("hide");
      //this.table.getTaskProductList();
      exportRefreshTable.emit(this.taskId);//刷新列表
      if (res.result_code === '0000') {
        //this.server.openWindow(res.httpPath)
      }
    }).catch((err: any) => {
      this.hintsService.messages("error", "error");
      return;
    });
  }

  public pathList:any;
  exportPathList(){
    let data = {
      token: "b25dbd7138cf48e09941087e6d9a2e93",
      pageNo:1,
      pageSize:20,
      startTime:null,
      endTime:null,
      queryCriteria:null
    }
    this.request.postRequest(this.server.baseUrl +appProductUrl.getExportPathList,data).then((res: any) => {
      if (res.result_code === '0000') {
        this.pathList = res.result;
      }else{
        //this.hintsService.messages(res.message, res.result_code);
      }
    });
  }

}
